home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Super Collection / Windows 95 Super Collection.iso / win95 / bench / thread / thrdomtr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-13  |  4.4 KB  |  167 lines

  1. // THRDOMTR.H : Declares CMainWindow class for THRDOMTR.EXE application.
  2.  
  3. #ifndef __THRDOMTR_H__
  4. #define __THRDOMTR_H__
  5.  
  6. #include "resource.h"
  7.  
  8. // 'Private' messages to signal threads have ended.
  9. #define PM_THREAD_STATUS_MSG             (WM_USER + 1)
  10. #define PM_FILE_THREAD_ENDED             (WM_USER + 2)
  11. #define PM_START_THREAD_PROCESSING  (WM_USER + 3)
  12.  
  13. const long BUFF_SIZE = 4096;
  14.  
  15. typedef struct _FILETHREADPARAMS
  16. {
  17.     char szFileName[256];
  18.     DWORD dwTotalBytes;
  19.     HWND hwndParent;
  20.     BOOL bIsAsync;
  21. } FILETHREADPARAMS;
  22.  
  23. typedef struct _THREADPARAMS
  24. {
  25.     int nDemoType;
  26.     BOOL bIsTimed;
  27.     int nThreadNum;
  28.     BOOL bUseWindow;
  29.     BOOL bUseMutex;
  30.     POINT ptWinStart;
  31.     HWND hwndParent;
  32. } THREADPARAMS;
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35.  
  36. // CMainWindow:
  37. // See THRDOMTR.cpp for the code to the member functions and the message map.
  38. //
  39. class CMainWindow : public CFrameWnd
  40. {
  41. public:
  42.     CMainWindow();
  43.  
  44.     //{{AFX_MSG( CMainWindow )
  45.     afx_msg void OnAbout();
  46.     afx_msg void OnThreadDemoOptions();
  47.     afx_msg void OnFileIOOptions();
  48.     afx_msg void OnPaint();
  49.     afx_msg void OnSize(UINT nType, int cx, int cy);
  50.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  51.     afx_msg void OnDoFileIODemo();
  52.     afx_msg void OnDoThreadDemo();
  53.     afx_msg void OnUpdateFileIODemo(CCmdUI* pCmdUI);
  54.     afx_msg LRESULT OnThreadStatusMsg(WPARAM uUnused, LPARAM lpszMsg);
  55.     afx_msg LRESULT OnFileThreadEnded(WPARAM uUnused, LPARAM lResult);
  56.     afx_msg void OnUpdateFileIOOptions(CCmdUI* pCmdUI);
  57.     afx_msg void OnUpdateThreadDemo(CCmdUI* pCmdUI);
  58.     afx_msg void OnUpdateThreadDemoOptions(CCmdUI* pCmdUI);
  59.     afx_msg void OnTimer(UINT nIDEvent);
  60.     afx_msg void OnDestroy();
  61.     //}}AFX_MSG
  62.    
  63.     void AddMsgToLB(CString& strMsg, BOOL bShowInStatusBarToo = TRUE);
  64.     
  65.     void AddMsgToLB(LPSTR lpszMsg, BOOL bShowInStatusBarToo = TRUE) {
  66.         CString s = lpszMsg;  AddMsgToLB(s, bShowInStatusBarToo); }
  67.  
  68.     void ClearMsgsInLB(BOOL bClearInStatusBarToo = TRUE) {
  69.             StatusLB.ResetContent(); StatusLB.UpdateWindow();
  70.             if(bClearInStatusBarToo) { StatusBar.SetWindowText(""); 
  71.                 StatusBar.UpdateWindow(); }
  72.         }
  73.  
  74.     void SetStatusMsg(CString& strMsg) { StatusBar.SetWindowText(strMsg.GetBuffer(255));
  75.          StatusBar.UpdateWindow(); }
  76.  
  77.     void SetStatusMsg(LPSTR lpszMsg) { StatusBar.SetWindowText(lpszMsg);
  78.          StatusBar.UpdateWindow(); }
  79.  
  80.     // Shows elapsed time in second panel...
  81.     void SetTimeMsg(CString& strTime)  { StatusBar.SetPaneText(1, strTime.GetBuffer(255));
  82.         StatusBar.UpdateWindow(); }
  83.     void SetTimeMsg(LPSTR lpszTime)  { StatusBar.SetPaneText(1, lpszTime); 
  84.         StatusBar.UpdateWindow(); }
  85.  
  86.     LPSTR GetElapsedTimeAsStr(DWORD dwEarlier, DWORD dwLater);
  87.     void ShowElapsedTime(DWORD dwEarlier, DWORD dwLater);
  88.  
  89.     int cxTextWidth;
  90.     int cyTextHeight;
  91.  
  92.     HANDLE hMutex;
  93.     
  94.     // Variables to track thread demo. settings.
  95.  
  96.     // For file I/O demo.
  97.     BOOL bFileIODemoStarted;
  98.     CString strWorkFileName;  // File for read/write test.
  99.     BOOL bDoAsynchronousFileIO;  // False for synchronous.
  100.     BOOL bDoFileWrite;  // FALSE = Do Read
  101.     UINT uFileKB;
  102.     HANDLE hThrdFileDemo;
  103.  
  104.     int cxScreen;
  105.     int cyScreen;
  106.  
  107.     // For thread demo.
  108.     BOOL bThreadDemoStarted;
  109.     HANDLE hThrd[64]; 
  110.     
  111.     // Coordinate of most recent thread window.
  112.     int xThrdWnd;
  113.     int yThrdWnd;
  114.     int cxThrdWnd;
  115.     int cyThrdWnd;
  116.  
  117.     // Elapsed time.
  118.     DWORD dwTimeStart;
  119.     DWORD dwTimeStop;
  120.  
  121.     // For thread demo.
  122.     int nThreadCount;
  123.     int nThreadCountActual;  // How many threads we successfully created.
  124.     int nTestType;
  125.     DWORD dwThreadPriorityClass;
  126.     BOOL bUseMutexObjects;  // FALSE = use Critical Sections.
  127.     BOOL bUseWindowPerThread; 
  128.  
  129.     // For both.    
  130.     BOOL bLogOutput;
  131.     HFILE hfLogFile;    
  132.     CString strLogFilename;
  133.     
  134.     // Controls in main window, needed to show demo. output
  135.     CStatic StatusLBLabel;
  136.     CListBox StatusLB;
  137.  
  138.     CStatusBar StatusBar;
  139.     
  140.     // Simple demo. error tracking.
  141.     int nErrCode;
  142.     CString sErrMsg;
  143.  
  144.     // These 'friend' procedures are used to run separate threads.
  145.     friend void FileWriteThreadProc(void *pParams);
  146.     friend void FileReadThreadProc(void *pParams);
  147.  
  148.     friend void ThreadDemoProc(void *pParams);
  149.     
  150.     DECLARE_MESSAGE_MAP()
  151. };
  152.  
  153. /////////////////////////////////////////////////////////////////////////////
  154.  
  155. // CTheApp:
  156. // See THRDOMTR.cpp for the code to the InitInstance member function.
  157. //
  158. class CTheApp : public CWinApp
  159. {
  160. public:
  161.     virtual BOOL InitInstance();
  162. };
  163.  
  164. /////////////////////////////////////////////////////////////////////////////
  165.  
  166. #endif // __THRDOMTR_H__
  167.